<template>
	<view class="firmware">
		<!-- #ifdef APP-PLUS -->
		<view class="status_bar">
			<view class="top_view"></view>
		</view>
		<!-- #endif -->
		<view class="firmware-top">
			<image src="/static/images/icon17.png" mode="widthFix" @click="gotoPage"></image>
			<text>固件升级</text>
		</view>
		<view class="firmware-title" v-if="onloadBtn">发现新版本</view>
		<view class="firmware-title" v-else>正在升级</view>
		<view class="firmware-con">
			<text>设备即将固件升级，请注意以下事项：</text>
			<view class="firmware-text">
				<view class="firmware-dian"></view>
				<text>升级时长</text>
			</view>
			<text>预计 10 分钟，请您提前预留充足时间。​</text>
			<view class="firmware-text">
				<view class="firmware-dian"></view>
				<text>设备状态</text>
			</view>
			<text>升级中设备暂不可用，期间可能会出现短暂无响应，属于正常现象，请勿强制操作设备。​</text>
			<view class="firmware-text">
				<view class="firmware-dian"></view>
				<text>语音提示</text>
			</view>
			<text>请留意设备语音提示，听到 “更新成功” 即表示升级结束。</text>
			<view class="firmware-text">
				<view class="firmware-dian"></view>
				<text>后续连接</text>
			</view>
			<text>升级成功后，设备会自动重启。重启完成后，您需要在 APP 上重新连接设备，即可恢复正常使用。</text>
		</view>
		<button v-if="onloadBtn" @click="onUpdata">立即更新</button>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				onloadBtn:true,
				sbClientid:'',
				sbIp:''
			}
		},
		onLoad(options) {
			this.sbIp = options.sbIp
			this.sbClientid = options.sbClientid
		},
		onShow() {
			
		},
		methods:{
			gotoPage(){
				uni.navigateBack(1)
			},
			onUpdata(){
				let that=this
				that.onloadBtn = false
				uni.showLoading({
					title: '下载安装中'
				});
				setTimeout(() => {
					that.onloadBtn = true
					uni.hideLoading();
				}, 3000);
				setTimeout(()=>{
					that.toast('安装中，请注意语音提示')
				},3500)
				setTimeout(()=>{
					uni.switchTab({
						url:'/pages/index/index'
					})
				},5000)
				const formData = {
					ope: 'E',
					sbbh:that.extractFrom20(that.sbClientid),
					hostname: 'qhdlink.lanyun.net',
					port: 55050,
					username: 'root',
					password:'p4o4zqf0xe9c7w37'
				}
				uni.request({
					url: 'http://'+that.sbIp+':8000',
					data: formData,
					header:{
						'content-type':'application/x-www-form-urlencoded'
					},
					method:'post',
					success: (res) => {
						console.log(res)
					}
				});
			}
		}
	}
</script>

<style lang="less" scoped>
	.firmware{
		width: 100%;
		height: 100vh;
		background: url('/static/images/bg6.png') no-repeat;
		background-size: 100% 100%;
	}
	.firmware-top{
		width: 100%;
		display: flex;
		align-items: center;
		position: relative;
		padding: 20upx 0;
		image{
			width: 40upx;
			height: auto;
			position: absolute;
			left: 40upx;
		}
		text{
			display: block;
			width: 100%;
			text-align: center;
			font-size: 32upx;
			color: #1A1A1A;
		}
	}
	.firmware-title{
		font-size: 80upx;
		color: #1C63CB;
		font-family: 'AHeiTi';
		font-weight: bold;
		text-align: center;
		margin-top: 430upx;
	}
	.firmware-con{
		width: 90%;
		margin: 20upx auto;
		border-radius: 16upx;
		background: #E6EDF4;
		padding: 40upx;
		box-sizing: border-box;
		text{
			display: block;
			font-size: 28upx;
			color: #1A1A1A;
		}
		.firmware-text{
			display: flex;
			align-items: center;
			margin-top: 10upx;
			.firmware-dian{
				width: 8upx;
				height: 8upx;
				border-radius: 50%;
				background: #1C63CB;
				margin-right: 10upx;
			}
			text{
				font-weight: bold;
			}
		}
	}
	button{
		width: 90%;
		margin: 40upx auto;
		border-radius: 60px;
		background: linear-gradient(0deg, #5EA9FA 0%, #7CB6F5 100%);
		color: #fff;
	}
</style>